﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DrSoftsFrame.Servers;
using PreeRegisterModel;
using System.Data.SqlClient;
using DrSoftsFrame;

namespace PreeRegisterDAL
{
    public class DepositPayDAL
    {
        /// <summary>
        /// 获取押金单据号
        /// </summary>
        /// <param name="deptid"></param>
        /// <returns></returns>
        public static string Up_ReturnDepositReceipNo()
        {
            ClinicDb mydb = new ClinicDb();
            try
            {
                string ReturnDepositReceipNo = "";

                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "Up_ReturnDepositReceipNo";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p1 = new SqlParameter("@ReturnDepositReceipNo", SqlDbType.VarChar,20);
                p1.Direction = ParameterDirection.Output;
                p1.Value = ReturnDepositReceipNo;
                cmd.Parameters.Add(p1);

                object[] ob = mydb.ExecuteSqlCmdWithOutParmList(cmd);
                ReturnDepositReceipNo = ob[0].ToString();
                return ReturnDepositReceipNo;
            }
            catch (Exception err)
            {
                throw err;
            }
        }

        /// <summary>
        /// 交住院押金  
        /// </summary>
        /// <param name="deptid"></param>
        /// <returns></returns>
        public static DataSet DepositPay(DepositPayRequestModel depositPayRequestModel,string DepositReceipNo)
        {
            ClinicDb mydb = new ClinicDb();
            try
            {
                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "Up_His_InterFace_InDespoit";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p1 = new SqlParameter("@InPcode", SqlDbType.VarChar,20);
                p1.Direction = ParameterDirection.Input;
                p1.Value = depositPayRequestModel.InPcode;
                cmd.Parameters.Add(p1);

                SqlParameter p2 = new SqlParameter("@PayMoney", SqlDbType.Decimal);
                p2.Direction = ParameterDirection.Input;
                p2.Value = depositPayRequestModel.PayMoney;
                cmd.Parameters.Add(p2);

                SqlParameter p3 = new SqlParameter("@DepositReceipNo", SqlDbType.VarChar, 20);
                p3.Direction = ParameterDirection.Input;
                p3.Value = DepositReceipNo;
                cmd.Parameters.Add(p3);

                SqlParameter p4 = new SqlParameter("@TransOp", SqlDbType.VarChar,10);
                p4.Direction = ParameterDirection.Input;
                p4.Value = depositPayRequestModel.userid;
                cmd.Parameters.Add(p4);

                SqlParameter p5 = new SqlParameter("@PayWay", SqlDbType.Int);
                p5.Direction = ParameterDirection.Input;
                p5.Value = depositPayRequestModel.payway;
                cmd.Parameters.Add(p5);

                DataSet ds = mydb.ExecuteSqlCmdFillDs(cmd);
                if (ds == null || ds.Tables.Count < 2||ds.Tables[1].Rows.Count<1)
                {
                    return null;
                }
                return ds;
            }
            catch (Exception err)
            {
                throw err;
            }
        }
    }
}
